package com.wd.buycar.view.adapter

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.wd.buycar.R
import com.wd.buycar.view.activity.NewCarDetailsActivity
import com.wd.common.bean.BuyCarBean

/**
 * 作者：马海钊
 * 时间：2023/9/11 17:23
 * 功能：
 */
class BuynewcarClooseAdapter(var context: Context, private var list: List<BuyCarBean.BuyNewCar_ChooseList.Result>) :
    RecyclerView.Adapter<BuynewcarClooseAdapter.ViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view =
            LayoutInflater.from(context).inflate(R.layout.buy_newcar_cloose_small, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.name.text = list[position].name
        holder.price.text = list[position].lowBid.toString()+"—1—"+list[position].highBid+"万"
        Glide.with(context).load(list[position].bgImageUrl)
            .error(R.mipmap.buy_oldcar_back1)
            .placeholder(R.mipmap.buy_oldcar_back1)
            .into(holder.imgid)
        holder.itemView.setOnClickListener {
            val intent = Intent(context, NewCarDetailsActivity::class.java)
            intent.putExtra("id",list.get(position).categoryId)
            intent.putExtra("name",list.get(position).name)
            context.startActivity(intent)
        }
    }

    override fun getItemCount(): Int {
        return list.size
    }

    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var name: TextView
        var price: TextView
        var imgid: ImageView

        init {
            name = itemView.findViewById(R.id.buy_newcar_cloose_small_name)
            price = itemView.findViewById(R.id.buy_newcar_cloose_small_price)
            imgid = itemView.findViewById(R.id.buy_newcar_cloose_small_imgid)
        }
    }
}